package org.musicguardian.core.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;

import org.apache.commons.collections.MultiHashMap;
import org.apache.commons.collections.map.MultiValueMap;

public class Model implements java.io.Serializable {
    private TreeSet<Library> localLibraries = new TreeSet<Library>();
    
    private MultiValueMap remoteLinks = new MultiValueMap();

    public Model() {
	super();
    }

    public Model addLocalLibrary(Library library) {
	if (!localLibraries.add(library)) {
	    Library knownLibrary = localLibraries.tailSet(library).first();
	    for (Iterator<Artist> iter = library.getArtists().iterator(); iter
		    .hasNext();) {
		knownLibrary.addArtist(iter.next());
	    }
	}
	return this;
    }

    public TreeSet<Library> getLocalLibraries() {
	return localLibraries;
    }
    
    public void addRemoteLink(RemoteLink link){
	remoteLinks.put(link.getLocalArtist(), link);
    }
    
    public List<RemoteLink> getRemoteLinks(Artist artist){
	return new ArrayList<RemoteLink>(remoteLinks.getCollection(artist));
    }
}
